Breadth First Search (BFS) algorithm